// pages/doctorPages/my/dateList/dateList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dateList: [{
      name: '周日',
      index: 0,
      checked: false
    },
    {
      name: '周一',
      index: 1,
      checked: false
    },
    {
      name: '周二',
      index: 2,
      checked: false
    },
    {
      name: '周三',
      index: 3,
      checked: false
    },
    {
      name: '周四',
      index: 4,
      checked: false
    },
    {
      name: '周五',
      index: 5,
      checked: false
    },
    {
      name: '周六',
      index: 6,
      checked: false
    }
    ],
    weeks: [],
    dateIndex: 0,
    rules: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let rules = options.rules;
    if (rules) {
      rules = JSON.parse(rules)
    }    
    this.setData({
      rules: rules,
      weeks: rules.weeks
    })

  },
  checkboxChange(e) {
    console.log(e)
    let weeks = e.detail.value;
    let rules = this.data.rules;
    rules.weeks = weeks;
    this.setData({
      rules:rules,
      weeks:weeks
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let that = this
    let dl = this.data.dateList.map(function (ele, index, array) {
      for (var i in that.data.weeks) {
        if (ele.index == that.data.weeks[i]) {
          ele.checked = true;
        }
      }
      return ele;
    });

    this.setData({
      dataList: dl
    })    
  },
  goSetRules(){
    console.log(this.data.rules)
    // wx.redirectTo({
    //   url: '/pages/doctorPages/my/addModal/addModal?rules='+ JSON.stringify(this.data.rules),
    // })
    var pages = getCurrentPages(); // 获取页面栈
    var prevPage = pages[pages.length - 2]; // 上一个页面
    prevPage.setData({
      test: this.data.rules
    })
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})